From 37030a771059f43ad701700380719d19cbc7c966 Mon Sep 17 00:00:00 2001 From: Benjamin Otte Date: Thu, 10 Jul 2014 18:31:15 +0200 Subject: [PATCH] label: Add ink rect support to GtkLabel --- gtk/gtklabel.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/gtk/gtklabel.c b/gtk/gtklabel.c index 9cc6ff92a9..b3fd1537a0 100644 --- a/gtk/gtklabel.c +++ b/gtk/gtklabel.c @@ -3955,12 +3955,31 @@ G_GNUC_END_IGNORE_DEPRECATIONS *yp = y; } +static void +gtk_label_get_ink_rect (GtkLabel *label, + GdkRectangle *rect) +{ + GtkLabelPrivate *priv = label->priv; + PangoRectangle ink_rect; + int x, y; + + gtk_label_ensure_layout (label); + get_layout_location (label, &x, &y); + pango_layout_get_pixel_extents (priv->layout, &ink_rect, NULL); + + rect->x = x + ink_rect.x; + rect->width = ink_rect.width; + rect->y = y + ink_rect.y; + rect->height = ink_rect.height; +} + static void gtk_label_size_allocate (GtkWidget *widget, GtkAllocation *allocation) { GtkLabel *label = GTK_LABEL (widget); GtkLabelPrivate *priv = label->priv; + GdkRectangle clip_rect; GTK_WIDGET_CLASS (gtk_label_parent_class)->size_allocate (widget, allocation); @@ -3975,6 +3994,9 @@ gtk_label_size_allocate (GtkWidget *widget, allocation->width, allocation->height); } + + gtk_label_get_ink_rect (label, &clip_rect); + gtk_widget_set_clip (widget, &clip_rect); } static void -- 2.30.2